package com.yqfk.controller;


import com.yqfk.auto.JSONAuthentication;
import com.yqfk.entity.YLevel;
import com.yqfk.entity.YPun;
import com.yqfk.mapper.YLevelMapper;
import com.yqfk.response.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.logging.Level;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yqfk
 * @since 2022-03-31
 */
@RestController
@RequestMapping("/y-level")
public class YLevelController extends JSONAuthentication {
    @Autowired
    YLevelMapper yLevelMapper;
    @ApiOperation(value = "修改疫情等级")
    @PostMapping("/upd")
    public void upd(HttpServletRequest request, HttpServletResponse response, @RequestParam("level") String  level) throws Exception {
        YLevel yLevel = yLevelMapper.selectById(1);
        yLevel.setLevel(level);
        if (yLevelMapper.updateById(yLevel) > 0) {
            Result ok = Result.ok();
            this.WriteJSON(request, response, ok);
        } else {
            Result error = Result.error();
            this.WriteJSON(request, response, error);
        }
    }
    @ApiOperation(value = "查看疫情等级")
    @PostMapping("/look")
    public void look(HttpServletRequest request, HttpServletResponse response) throws Exception {
        YLevel yLevel = yLevelMapper.selectById(1);
            Result ok = Result.ok().data("level",yLevel);
            this.WriteJSON(request, response, ok);

    }
}

